Byteasar has a pack of
cards that he likes to shuffle. The
positions of cards are numbered from
to
. Byteasar has
acquired such a skill in shuffling that each time he obtains the same
arrangement, i.e. a card from the
-th position (
) always goes to the same
-th position. We denote by
the position of the
-th card (i.e. the card initially
placed at the
-th position) after Byteasar repeated shuffling
times.
Write a program which:
and
and
the sequence of numbers
,
,
In the first line of the standard input there are two positive integers
and
(
,
). In the consecutive
lines there are successive
elements of the sequence
, one per line. In the (
)-st line there is a positive integer
: the final position
of the card from the
-th position,
.
Your program should write to the standard output
integers:
successive elements of the sequence
, one per line. In the
-th line there should be one number
: the position of
the card from the
-th position after a single shuffle. You may
assume that for the test data there always exist the desired sequence
. If there are many such sequences your program should write one
of them (arbitrary).
For the input data:
5 2 1 2 5 3 4
the correct result is:
1 2 4 5 3
or:
2 1 4 5 3
Task author: Pawel Parys.
In the event of technical difficulties with Szkopuł, please contact us via email at [email protected].
If you would like to talk about tasks, solutions or technical problems, please visit our Discord servers. They are moderated by the community, but members of the support team are also active there.